package com.addcn.pushlibrary.utils.catchs;

import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;

/**
 * 用于缓存标记类型的数据工具类
 * 退出程序不清楚
 * @author luwenbo@addcn.com
 *
 */
public class LSharedUtil {


/**数据存储文件*/
public static String MEMBER_USER = "l_library";
public static int MEMBER_MODEL = Activity.MODE_PRIVATE;

public LSharedUtil(Context context, String[] prefGroups) {
    super();
}

 /**
* 保存一个int类型的值！
* @param context
* @param key
* @param value
* @return
*/
public static boolean putInt(Context context,String key, int value) {
        SharedPreferences preferences = context.getSharedPreferences(MEMBER_USER, MEMBER_MODEL);
Editor editor = preferences.edit();
editor.putInt(key, value);
return editor.commit();
}
/**
* 保存一个String类型的值！
* @param context
* @param key
* @param value
* @return
*/
public static boolean putString(Context context, String key, String value) {
    SharedPreferences preferences = context.getSharedPreferences(MEMBER_USER, MEMBER_MODEL);
    Editor editor = preferences.edit();
    editor.putString(key, value);
    return editor.commit();
}


/**
* 保存一个boolean类型的值！
* @param context
* @param key
* @param value
* @return
*/
public static boolean putBoolean(Context context, String key, boolean value) {
    SharedPreferences preferences = context.getSharedPreferences(MEMBER_USER, MEMBER_MODEL);
    Editor editor = preferences.edit();
    editor.putBoolean(key, value);
    return editor.commit();
}

/**
*
* 创建人：10528
* 创建时间：2015/10/16 下午5:26:45
* 方法描述：
* @param context
* @param key
* @param value
* @return
*/
public static boolean putLong(Context context, String key, long value) {
    SharedPreferences preferences = context.getSharedPreferences(MEMBER_USER, MEMBER_MODEL);
    Editor editor = preferences.edit();
    editor.putLong(key, value);
    return editor.commit();
}

/**
* 获取int的value
*
* @param context
* @param key
* 名字
* @param defValue
* 默认值
* @return
*/
public static int getInt(Context context, String key, int defValue) {
    SharedPreferences preferences = context.getSharedPreferences(MEMBER_USER, MEMBER_MODEL);
    if (preferences != null){
        return preferences.getInt(key, defValue);
    }else{
        return defValue;
    }
}
/**
*
* 创建人：10528
* 创建时间：2015/10/16 下午5:27:41
* 方法描述：
* @param context
* @param key
* @param defValue
* @return
*/
public static long getLong(Context context, String key, long defValue) {
    SharedPreferences preferences = context.getSharedPreferences(MEMBER_USER, MEMBER_MODEL);
    return preferences.getLong(key, defValue);
}

/**
* 获取String的value
*
* @param context
* @param key
* 名字
* @param defValue
* 默认值
* @return
*/
public static String getString(Context context, String key, String defValue) {
    SharedPreferences preferences = context.getSharedPreferences(MEMBER_USER, MEMBER_MODEL);
return preferences.getString(key, defValue);
}

public static String getString(Context context, String key) {
    SharedPreferences preferences = context.getSharedPreferences(MEMBER_USER, MEMBER_MODEL);
return preferences.getString(key, "");
}


/**
* 获取boolean的value
*
* @param context
* @param key
* 名字
* @param defValue
* 默认值
* @return
*/
public static boolean getBoolean(Context context, String key, boolean defValue) {
    SharedPreferences preferences = context.getSharedPreferences(MEMBER_USER, MEMBER_MODEL);
    return preferences.getBoolean(key, defValue);
}
public static boolean getBoolean(Context context, String key) {
    SharedPreferences preferences = context.getSharedPreferences(MEMBER_USER, MEMBER_MODEL);
    return preferences.getBoolean(key, false);
}



/**
* 清除对应的key的值
* @param context
* @param key
* 名字
*/
public static void remove(Context context, String key) {
    SharedPreferences preferences = context.getSharedPreferences(MEMBER_USER, MEMBER_MODEL);
     preferences.edit().remove(key).commit();
}

/**
*
*清除缓存
*/
public static void clear(Context context) {
    SharedPreferences preferences = context.getSharedPreferences(MEMBER_USER, MEMBER_MODEL);
    preferences.edit().commit();


}


}
